---
title: Nexus Framework Prisma Users
---

## Hello Nexus Framework Prisma User!

If you're looking to migrate from the Nexus Framework over to Nexus and you're using the Prisma plugin, this guide is for you.

**This guide assumes you've already followed the [Framework Users adoption Guide](/adoption-guides/nexus-framework-users).**

## Dependencies

You will need to install the Prisma dependencies yourself now.

```
npm install -D @prisma/cli
npm install @prisma/client
```

You must also make sure that you are using the version `0.20` or later of `nexus-plugin-prisma`.

## Enabling the plugin

You will now need to work with the `makeSchema` API of `nexus` directly.

```ts diff
-import { use } from 'nexus'
-import { prisma } from 'nexus-plugin-prisma'
+import { makeSchema } from 'nexus'
+import { nexusPrisma } from 'nexus-plugin-prisma'

-use(prisma())

+export const schema = makeSchema({
+  plugins: [nexusPrisma()]
+})
```

## Configuring the plugin

There are a number of defaults that the framework used to provide for you. Here's how you can configure the schema plugin to behave the same.

### Enabling CRUD capabilities

If you were using `t.crud` with the framework, you must also explicitly enable it with the schema plugin

```ts diff
import { makeSchema } from 'nexus'
import { nexusPrisma } from 'nexus-plugin-prisma'

makeSchema({
  plugins: [nexusPrisma({
+   experimentalCRUD: true
  })]
})
```

### Configuring Backing types

To let `nexus` know of the Prisma Client types so that, for instance, your resolvers expect the right types, you must point `makeSchema` to the Prisma Client where all the types are exported.

```ts diff
import { makeSchema } from 'nexus'
import { nexusPrisma } from 'nexus-plugin-prisma'

export const schema = makeSchema({
+  sourceTypes: {
+    modules: [
+      {
+        module: require.resolve('.prisma/client/index.d.ts'),
+        alias: "prisma",
+      }
+    ]
+  }
  plugins: [
    nexusPrisma({
      experimentalCRUD: true
    })
  ]
})
```

### Configuring Context Type

The framework used to automatically inject and type your context so that an instance of the client would be there for you. We now need to configure that manually. To do so, we'll first create a `context.ts` file where we'll export a type containing the Prisma Client.

```tsx
// context.ts
import { PrismaClient } from '@prisma/client'

export type Context = {
  db: PrismaClient
}
```

Then, we'll go back to the file where we're calling `makeSchema`, and add the following configuration

```ts diff
import { makeSchema } from 'nexus'
import { nexusPrisma } from 'nexus-plugin-prisma'

export const schema = makeSchema({
  sourceTypes: {
    modules: [
      {
        source: require.resolve('.prisma/client/index.d.ts'),
        alias: "prisma",
      },
    ],
+   contextType: {
+     source: require.resolve('./context'),
+     alias: 'ContextModule'
+   }
  }
  plugins: [
    nexusPrisma({
      experimentalCRUD: true
    })
  ]
})
```

### Configuring Custom Scalars

If your Prisma Schema is using either the `Json` or `DateTime` type, the framework used to provide some GraphQL scalars to map these. With `nexus`, you will need to install and do the mapping yourself.

1.  Start by installing the following dependency

    ```bash
    npm install graphql-scalars
    ```xf

2.  Then, add the following configuration property to the Prisma plugin

    ```ts diff
    import { makeSchema } from 'nexus'
    import { nexusPrisma } from 'nexus-plugin-prisma'
    +import { DateTimeResolver, JSONObjectResolver } from 'graphql-scalars'

    export const schema = makeSchema({
      sourceTypes: {
        modules: [
          {
            module: require.resolve('.prisma/client/index.d.ts'),
            alias: "prisma",
          },
        ],
        contextType: {
          module: require.resolve('./context'),
          alias: 'ContextModule'
        }
      }
      plugins: [
        nexusPrisma({
          experimentalCRUD: true
    +     scalars: {
    +       DateTime: DateTimeResolver,
    +       Json: new GraphQLScalarType({
    +         ...JSONObjectResolver,
    +         name: 'Json',
    +         description: 'The `JSON` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',
    +       })
    +     }
        })
      ]
    })
    ```

## Using the plugin

Once the plugin is enabled and properly configured, **none of your actual code usage of `nexus-plugin-prisma` (like `t.model` or `t.crud` calls) should have to change.**

The framework plugin however was giving you a couple of conveniences in terms of development workflow. Indeed, the framework plugin was:

- Regenerating the Prisma Client for you everytime you'd run `nexus dev`
- Regenerating the Prisma Client after you'd edit your `schema.prisma` file and migrate your database

This means you now have to manually regenerate the Prisma Client after migrating your database. To do this, use the Prisma CLI and run the following command:

```
npx prisma generate
```

Although you already had to run the command manually with the framework plugin, here's an additional quick reminder on how to run database migrations with Prisma Migrate:

To generate a migrate file and apply the migration, run:

```
npx prisma migrate dev --preview-feature
```
